home *** CD-ROM | disk | FTP | other *** search
/ Hot Super Models / Hot Super Models.iso / unix / x11 / xv2r1.tar / xv2r1 / extensions / xv / lib / Xv.c < prev   
C/C++ Source or Header  |  1991-06-26  |  16KB  |  848 lines

  1. /***********************************************************
  2. Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24. /*
  25. ** File: 
  26. **
  27. **   Xv.c --- Xv library extension module.
  28. **
  29. ** Author: 
  30. **
  31. **   David Carver (Digital Workstation Engineering/Project Athena)
  32. **
  33. ** Revisions:
  34. **
  35. **   26.06.91 Carver
  36. **     - changed XvFreeAdaptors to XvFreeAdaptorInfo
  37. **     - changed XvFreeEncodings to XvFreeEncodingInfo
  38. **
  39. **   11.06.91 Carver
  40. **     - changed SetPortControl to SetPortAttribute
  41. **     - changed GetPortControl to GetPortAttribute
  42. **     - changed QueryBestSize
  43. **
  44. **   15.05.91 Carver
  45. **     - version 2.0 upgrade
  46. **
  47. **   240.01.91 Carver
  48. **     - version 1.4 upgrade
  49. **
  50. */
  51.  
  52. #include "Xvlibint.h"
  53.  
  54. static XExtCodes *_XvCodes;
  55. static Bool (* _XvOldWireToEventVideo)();
  56. static Bool (* _XvOldWireToEventPort)();
  57. static char *(* _XvOldErrorString)();
  58.  
  59. static Bool _XvWireToEvent();
  60. static char *_XvErrorString();
  61.  
  62. #define    PREAMBLE(stat) \
  63.   LockDisplay(dpy); \
  64.   if ((!_XvCodes) && (!_XvInitExtension(dpy))) \
  65.     { \
  66.       UnlockDisplay(dpy); SyncHandle(); return (stat); \
  67.     }
  68.  
  69. #define POSTAMBLE \
  70.   UnlockDisplay(dpy); \
  71.   SyncHandle()
  72.  
  73. XvQueryExtension(dpy, p_version, p_revision, 
  74.          p_requestBase, p_eventBase, p_errorBase)
  75. register Display *dpy;
  76. unsigned int *p_version, *p_revision;
  77. unsigned int *p_requestBase, *p_eventBase, *p_errorBase;
  78.  
  79. {
  80.   register xvQueryExtensionReq *req;
  81.   xvQueryExtensionReply rep;
  82.  
  83.   PREAMBLE(XvBadExtension);
  84.  
  85.   XvGetReq(QueryExtension, req);
  86.  
  87.   /* READ THE REPLY */
  88.  
  89.   if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) 
  90.     {
  91.       UnlockDisplay(dpy);
  92.       SyncHandle();
  93.       return(XvBadExtension);
  94.     }
  95.  
  96.   *p_version = rep.version;
  97.   *p_revision = rep.revision;
  98.   *p_requestBase = _XvCodes->major_opcode;
  99.   *p_eventBase = _XvCodes->first_event;
  100.   *p_errorBase = _XvCodes->first_error;
  101.  
  102.   return Success;
  103. }
  104.  
  105. XvQueryAdaptors(dpy, window, p_nAdaptors, p_pAdaptors)
  106.  
  107. register Display *dpy;
  108. Window window;
  109. unsigned int *p_nAdaptors;
  110. XvAdaptorInfo **p_pAdaptors;
  111. {
  112.   register xvQueryAdaptorsReq *req;
  113.   xvQueryAdaptorsReply rep;
  114.   int size,ii,jj;
  115.   char *name;
  116.   XvAdaptorInfo *pas, *pa;
  117.   XvFormat *pfs, *pf;
  118.   char *buffer;
  119.   union 
  120.     {
  121.       char *buffer;
  122.       char *string;
  123.       xvAdaptorInfo *pa;
  124.       xvFormat *pf;
  125.     } u;
  126.   
  127.   PREAMBLE(XvBadExtension);
  128.  
  129.   XvGetReq(QueryAdaptors, req);
  130.   req->window = window;
  131.  
  132.   /* READ THE REPLY */
  133.  
  134.   if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) 
  135.     {
  136.       UnlockDisplay(dpy);
  137.       SyncHandle();
  138.       return(XvBadReply);
  139.     }
  140.  
  141.   size = rep.length << 2;
  142.   if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL)
  143.     {
  144.       UnlockMutex(&lock);
  145.       return(XvBadAlloc);
  146.     }
  147.   _XRead (dpy, buffer, size);
  148.  
  149.   u.buffer = buffer;
  150.  
  151.   /* GET INPUT ADAPTORS */
  152.  
  153.   size = rep.num_adaptors*sizeof(XvAdaptorInfo);
  154.   if ((pas=(XvAdaptorInfo *)Xmalloc(size))==NULL)
  155.     {
  156.       Xfree(buffer);
  157.       UnlockDisplay(dpy);
  158.       SyncHandle();
  159.       return(XvBadAlloc);
  160.     }
  161.  
  162.   /* INIT ADAPTOR FIELDS */
  163.  
  164.   pa = pas;
  165.   for (ii=0; ii<rep.num_adaptors; ii++)
  166.     {
  167.       pa->num_adaptors = 0;
  168.       pa->name = (char *)NULL;
  169.       pa->formats = (XvFormat *)NULL;
  170.     }
  171.  
  172.   pa = pas;
  173.   for (ii=0; ii<rep.num_adaptors; ii++)
  174.     {
  175.       pa->type = u.pa->type;
  176.       pa->base_id = u.pa->base_id;
  177.       pa->num_ports = u.pa->num_ports;
  178.       pa->num_formats = u.pa->num_formats;
  179.       pa->num_adaptors = rep.num_adaptors - ii;
  180.  
  181.       /* GET ADAPTOR NAME */
  182.  
  183.       size = u.pa->name_size;
  184.       u.buffer += (sz_xvAdaptorInfo + 3) & ~3;
  185.  
  186.       if ( (name = (char *)Xmalloc(size+1)) == NULL)
  187.     {
  188.       XvFreeAdaptorInfo(pas);
  189.       Xfree(buffer);
  190.       UnlockDisplay(dpy);
  191.       SyncHandle();
  192.       return(XvBadAlloc);
  193.     }
  194.       (void)strncpy(name, u.string, size);
  195.       pa->name = name;
  196.  
  197.       u.buffer += (size + 3) & ~3;
  198.  
  199.       /* GET FORMATS */
  200.  
  201.       size = pa->num_formats*sizeof(XvFormat);
  202.       if ((pfs=(XvFormat *)Xmalloc(size))==NULL)
  203.     {
  204.       XvFreeAdaptorInfo(pas);
  205.       Xfree(buffer);
  206.       UnlockDisplay(dpy);
  207.       SyncHandle();
  208.       return(XvBadAlloc);
  209.     }
  210.  
  211.       pf = pfs;
  212.       for (ii=0; ii<pa->num_formats; ii++)
  213.     {
  214.       pf->depth = u.pf->depth;
  215.       pf->visual_id = u.pf->visual;
  216.       pf++;
  217.       
  218.       u.buffer += (sz_xvFormat + 3) & ~3;
  219.     }
  220.  
  221.       pa->formats = pfs;
  222.  
  223.       pa++;
  224.  
  225.     }
  226.  
  227.   *p_nAdaptors = rep.num_adaptors;
  228.   *p_pAdaptors = pas;
  229.  
  230.   POSTAMBLE;
  231.  
  232.   return (Success);
  233. }
  234.  
  235.  
  236. void
  237. XvFreeAdaptorInfo(pAdaptors)
  238.  
  239. XvAdaptorInfo *pAdaptors;
  240.  
  241. {
  242.  
  243.   XvEncodingInfo *pe;
  244.   XvAdaptorInfo *pa;
  245.   int ii;
  246.  
  247.   if (!pAdaptors) return;
  248.  
  249.   pa = pAdaptors;
  250.  
  251.   for (ii=0; ii<pAdaptors->num_adaptors; ii++, pa++)
  252.     {
  253.       if (pa->name)
  254.     {
  255.       Xfree(pa->name);
  256.     }
  257.       if (pa->formats)
  258.     {
  259.       Xfree(pa->formats);
  260.     }
  261.     } 
  262.  
  263.   Xfree(pAdaptors);
  264.  
  265. }
  266.  
  267.  
  268. XvQueryEncodings(dpy, port, p_nEncodings, p_pEncodings)
  269.  
  270. register Display *dpy;
  271. XvPortID port;
  272. unsigned int *p_nEncodings;
  273. XvEncodingInfo **p_pEncodings;
  274. {
  275.   register xvQueryEncodingsReq *req;
  276.   xvQueryEncodingsReply rep;
  277.   int size,ii,jj;
  278.   char *name;
  279.   XvEncodingInfo *pes, *pe;
  280.   char *buffer;
  281.   union 
  282.     {
  283.       char *buffer;
  284.       char *string;
  285.       xvEncodingInfo *pe;
  286.     } u;
  287.   
  288.   PREAMBLE(XvBadExtension);
  289.  
  290.   XvGetReq(QueryEncodings, req);
  291.   req->port = port;
  292.  
  293.   /* READ THE REPLY */
  294.  
  295.   if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) 
  296.     {
  297.       UnlockDisplay(dpy);
  298.       SyncHandle();
  299.       return(NULL);
  300.     }
  301.  
  302.   size = rep.length << 2;
  303.   if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL)
  304.     {
  305.       UnlockMutex(&lock);
  306.       return(XvBadAlloc);
  307.     }
  308.   _XRead (dpy, buffer, size);
  309.  
  310.   u.buffer = buffer;
  311.  
  312.   /* GET ENCODINGS */
  313.  
  314.   size = rep.num_encodings*sizeof(XvEncodingInfo);
  315.   if ( (pes = (XvEncodingInfo *)Xmalloc(size)) == NULL)
  316.     {
  317.       Xfree(buffer);
  318.       UnlockDisplay(dpy);
  319.       SyncHandle();
  320.       return(XvBadAlloc);
  321.     }
  322.  
  323.   /* INITIALIZE THE ENCODING POINTER */
  324.  
  325.   pe = pes;
  326.   for (jj=0; jj<rep.num_encodings; jj++)
  327.     {
  328.       pe->name = (char *)NULL;
  329.       pe->num_encodings = 0;
  330.       pe++;
  331.     }
  332.  
  333.   pe = pes;
  334.   for (jj=0; jj<rep.num_encodings; jj++)
  335.     {
  336.       pe->encoding_id = u.pe->encoding;
  337.       pe->width = u.pe->width;
  338.       pe->height = u.pe->height;
  339.       pe->rate.numerator = u.pe->rate.numerator;
  340.       pe->rate.denominator = u.pe->rate.denominator;
  341.       pe->num_encodings = rep.num_encodings - jj;
  342.  
  343.       size = u.pe->name_size;
  344.       u.buffer += (sz_xvEncodingInfo + 3) & ~3;
  345.  
  346.       if ( (name = (char *)Xmalloc(size+1)) == NULL)
  347.     {
  348.       Xfree(buffer);
  349.       UnlockDisplay(dpy);
  350.       SyncHandle();
  351.       return(XvBadAlloc);
  352.     }
  353.       strncpy(name, u.string, size);
  354.       pe->name = name;
  355.       pe++;
  356.  
  357.       u.buffer += (size + 3) & ~3;
  358.  
  359.     }
  360.  
  361.   *p_nEncodings = rep.num_encodings;
  362.   *p_pEncodings = pes;
  363.  
  364.   POSTAMBLE;
  365.  
  366.   return (Success);
  367. }
  368.  
  369. void
  370. XvFreeEncodingInfo(pEncodings)
  371.  
  372. XvEncodingInfo *pEncodings;
  373.  
  374. {
  375.  
  376.   XvEncodingInfo *pe;
  377.   int ii;
  378.  
  379.   if (!pEncodings) return;
  380.  
  381.   pe = pEncodings;
  382.  
  383.   for (ii=0; ii<pEncodings->num_encodings; ii++, pe++)
  384.     {
  385.       if (pe->name) Xfree(pe->name);
  386.     }
  387.  
  388.   Xfree(pEncodings);
  389.  
  390. }
  391.  
  392. XvPutVideo(dpy, port, d, gc, vx, vy, vw, vh, dx, dy, dw, dh)
  393.  
  394. register Display *dpy;
  395. XvPortID port;
  396. Drawable d;
  397. GC gc;
  398. int vx, vy, dx, dy;
  399. unsigned int vw, vh;
  400. unsigned int dw, dh;
  401.  
  402. {
  403.   int size;
  404.   register xvPutVideoReq *req;
  405.  
  406.   PREAMBLE(XvBadExtension);
  407.   
  408.   FlushGC(dpy, gc);
  409.  
  410.   XvGetReq(PutVideo, req);
  411.  
  412.   req->port = port;
  413.   req->drawable = d;
  414.   req->gc = gc->gid;
  415.   req->vid_x = vx;
  416.   req->vid_y = vy;
  417.   req->vid_w = vw;
  418.   req->vid_h = vh;
  419.   req->drw_x = dx;
  420.   req->drw_y = dy;
  421.   req->drw_w = dw;
  422.   req->drw_h = dh;
  423.  
  424.   POSTAMBLE;
  425.  
  426.   return Success;
  427. }
  428.  
  429.  
  430. XvPutStill(dpy, port, d, gc, vx, vy, vw, vh, dx, dy, dw, dh)
  431.  
  432. register Display *dpy;
  433. XvPortID port;
  434. Drawable d;
  435. GC gc;
  436. int vx, vy, dx, dy;
  437. unsigned int vw, vh;
  438. unsigned int dw, dh;
  439.  
  440. {
  441.   int size;
  442.   register xvPutStillReq *req;
  443.  
  444.   PREAMBLE(XvBadExtension);
  445.  
  446.   FlushGC(dpy, gc);
  447.  
  448.   XvGetReq(PutStill, req);
  449.   req->port = port;
  450.   req->drawable = d;
  451.   req->gc = gc->gid;
  452.   req->vid_x = vx;
  453.   req->vid_y = vy;
  454.   req->vid_w = vw;
  455.   req->vid_h = vh;
  456.   req->drw_x = dx;
  457.   req->drw_y = dy;
  458.   req->drw_w = dw;
  459.   req->drw_h = dh;
  460.  
  461.   POSTAMBLE;
  462.  
  463.   return Success;
  464. }
  465.  
  466. XvGetVideo(dpy, port, d, gc, vx, vy, vw, vh, dx, dy, dw, dh)
  467.  
  468. register Display *dpy;
  469. XvPortID port;
  470. Drawable d;
  471. GC gc;
  472. int vx, vy, dx, dy;
  473. unsigned int vw, vh;
  474. unsigned int dw, dh;
  475.  
  476. {
  477.   int size;
  478.   register xvGetVideoReq *req;
  479.  
  480.   PREAMBLE(XvBadExtension);
  481.  
  482.   FlushGC(dpy, gc);
  483.  
  484.   XvGetReq(GetVideo, req);
  485.   req->port = port;
  486.   req->drawable = d;
  487.   req->gc = gc->gid;
  488.   req->vid_x = vx;
  489.   req->vid_y = vy;
  490.   req->vid_w = vw;
  491.   req->vid_h = vh;
  492.   req->drw_x = dx;
  493.   req->drw_y = dy;
  494.   req->drw_w = dw;
  495.   req->drw_h = dh;
  496.  
  497.   POSTAMBLE;
  498.  
  499.   return Success;
  500. }
  501.  
  502. XvGetStill(dpy, port, d, gc, vx, vy, vw, vh, dx, dy, dw, dh)
  503.  
  504. register Display *dpy;
  505. XvPortID port;
  506. Drawable d;
  507. GC gc;
  508. int vx, vy, dx, dy;
  509. unsigned int vw, vh;
  510. unsigned int dw, dh;
  511.  
  512. {
  513.   int size;
  514.   register xvGetStillReq *req;
  515.  
  516.   PREAMBLE(XvBadExtension);
  517.  
  518.   FlushGC(dpy, gc);
  519.  
  520.   XvGetReq(GetStill, req);
  521.   req->port = port;
  522.   req->drawable = d;
  523.   req->gc = gc->gid;
  524.   req->vid_x = vx;
  525.   req->vid_y = vy;
  526.   req->vid_w = vw;
  527.   req->vid_h = vh;
  528.   req->drw_x = dx;
  529.   req->drw_y = dy;
  530.   req->drw_w = dw;
  531.   req->drw_h = dh;
  532.  
  533.   POSTAMBLE;
  534.  
  535.   return Success;
  536. }
  537.  
  538.  
  539. XvStopVideo(dpy, port, draw)
  540.  
  541. register Display *dpy;
  542. XvPortID port;
  543. Drawable draw;
  544.  
  545. {
  546.   register xvStopVideoReq *req;
  547.  
  548.   PREAMBLE(XvBadExtension);
  549.  
  550.   XvGetReq(StopVideo, req);
  551.   req->port = port;
  552.   req->drawable = draw;
  553.  
  554.   POSTAMBLE;
  555.  
  556.   return Success;
  557. }
  558.  
  559. XvGrabPort(dpy, port, time)
  560.      register Display *dpy;
  561.      XvPortID port;
  562.      Time time;
  563.  
  564. {
  565.   int result;
  566.   xvGrabPortReply rep;
  567.   register xvGrabPortReq *req;
  568.  
  569.   PREAMBLE(XvBadExtension);
  570.  
  571.   XvGetReq(GrabPort, req);
  572.   req->port = port;
  573.   req->time = time;
  574.  
  575.   if (_XReply (dpy, (xReply *) &rep, 0, xTrue) == 0) 
  576.     rep.result = GrabSuccess;
  577.  
  578.   result = rep.result;
  579.  
  580.   POSTAMBLE;
  581.  
  582.   return result;
  583. }
  584.  
  585. XvUngrabPort(dpy, port, time)
  586.      register Display *dpy;
  587.      XvPortID port;
  588.      Time time;
  589.  
  590. {
  591.   register xvUngrabPortReq *req;
  592.  
  593.   PREAMBLE(XvBadExtension);
  594.  
  595.   XvGetReq(UngrabPort, req);
  596.   req->port = port;
  597.   req->time = time;
  598.  
  599.   POSTAMBLE;
  600.  
  601.   return Success;
  602. }
  603.  
  604. XvSelectVideoNotify(dpy, drawable, onoff)
  605.  
  606. register Display *dpy;
  607. Drawable drawable;
  608. Bool onoff;
  609.  
  610. {
  611.   register xvSelectVideoNotifyReq *req;
  612.  
  613.   PREAMBLE(XvBadExtension);
  614.  
  615.   XvGetReq(SelectVideoNotify, req);
  616.   req->drawable = drawable;
  617.   req->onoff = onoff;
  618.  
  619.   POSTAMBLE;
  620.  
  621.   return Success;
  622. }
  623.  
  624. XvSelectPortNotify(dpy, port, onoff)
  625.  
  626. register Display *dpy;
  627. XvPortID port;
  628. Bool onoff;
  629.  
  630. {
  631.   register xvSelectPortNotifyReq *req;
  632.  
  633.   PREAMBLE(XvBadExtension);
  634.  
  635.   XvGetReq(SelectPortNotify, req);
  636.   req->port = port;
  637.   req->onoff = onoff;
  638.  
  639.   POSTAMBLE;
  640.  
  641.   return Success;
  642. }
  643.  
  644.  
  645. XvSetPortAttribute (dpy, port, attribute, value)
  646.      register Display *dpy;
  647.      XvPortID port;
  648.      Atom attribute;
  649.      int value;
  650. {
  651.   register xvSetPortAttributeReq *req;
  652.  
  653.   PREAMBLE(XvBadExtension);
  654.  
  655.   XvGetReq(SetPortAttribute, req);
  656.   req->port = port;
  657.   req->attribute = attribute;
  658.   req->value = value;
  659.  
  660.   POSTAMBLE;
  661.  
  662.   return (Success);
  663. }
  664.  
  665. XvGetPortAttribute (dpy, port, attribute, p_value)
  666.      register Display *dpy;
  667.      XvPortID port;
  668.      Atom attribute;
  669.      int *p_value;
  670. {
  671.   register xvGetPortAttributeReq *req;
  672.   xvGetPortAttributeReply rep;
  673.  
  674.   PREAMBLE(XvBadExtension);
  675.  
  676.   XvGetReq(GetPortAttribute, req);
  677.   req->port = port;
  678.   req->attribute = attribute;
  679.  
  680.   /* READ THE REPLY */
  681.  
  682.   if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) 
  683.     {
  684.       UnlockDisplay(dpy);
  685.       SyncHandle();
  686.       return(XvBadReply);
  687.     }
  688.  
  689.   *p_value = rep.value;
  690.   
  691.   POSTAMBLE;
  692.  
  693.   return (Success);
  694. }
  695.  
  696. XvQueryBestSize(dpy, port, motion, vid_w, vid_h, drw_w, drw_h, 
  697.         p_actual_width, p_actual_height)
  698.      register Display *dpy;
  699.      XvPortID port;
  700.      Bool motion;
  701.      unsigned int vid_w, vid_h;
  702.      unsigned int drw_w, drw_h;
  703.      unsigned int *p_actual_width, *p_actual_height;
  704. {
  705.   register xvQueryBestSizeReq *req;
  706.   xvQueryBestSizeReply rep;
  707.  
  708.   PREAMBLE(XvBadExtension);
  709.  
  710.   XvGetReq(QueryBestSize, req);
  711.   req->port = port;
  712.   req->motion = motion;
  713.   req->vid_w = vid_w;
  714.   req->vid_h = vid_h;
  715.   req->drw_w = drw_w;
  716.   req->drw_h = drw_h;
  717.  
  718.   /* READ THE REPLY */
  719.  
  720.   if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) 
  721.     {
  722.       UnlockDisplay(dpy);
  723.       SyncHandle();
  724.       return(XvBadReply);
  725.     }
  726.  
  727.   *p_actual_width = rep.actual_width;
  728.   *p_actual_height = rep.actual_height;
  729.  
  730.   POSTAMBLE;
  731.  
  732.   return (Success);
  733. }
  734.  
  735. static Bool
  736. _XvWireToEvent(dpy, re, event)
  737. register Display *dpy;    /* pointer to display structure */
  738. register XvEvent *re;    /* pointer to where event should be reformatted */
  739. register xvEvent *event;    /* protocol event */
  740.  
  741. {
  742.  
  743.   if (event->u.u.type == _XvCodes->first_event+XvVideoNotify)
  744.     {
  745.       re->xvvideo.type = event->u.u.type & 0x7f;
  746.       re->xvvideo.serial = 
  747.     _XSetLastRequestRead(dpy, (xGenericReply *)event);
  748.       re->xvvideo.send_event = ((event->u.u.type & 0x80) != 0);
  749.       re->xvvideo.display = dpy;
  750.       re->xvvideo.time = event->u.videoNotify.time;
  751.       re->xvvideo.reason = event->u.videoNotify.reason;
  752.       re->xvvideo.drawable = event->u.videoNotify.drawable;
  753.       re->xvvideo.port_id = event->u.videoNotify.port;
  754.       if (_XvOldWireToEventVideo) 
  755.     {
  756.       (void)(* _XvOldWireToEventVideo)(dpy, re, event);
  757.     }
  758.     }
  759.   else if (event->u.u.type == _XvCodes->first_event+XvPortNotify)
  760.     {
  761.       re->xvport.type = event->u.u.type & 0x7f;
  762.       re->xvport.serial = 
  763.     _XSetLastRequestRead(dpy, (xGenericReply *)event);
  764.       re->xvport.send_event = ((event->u.u.type & 0x80) != 0);
  765.       re->xvport.display = dpy;
  766.       re->xvport.time = event->u.portNotify.time;
  767.       re->xvport.port_id = event->u.portNotify.port;
  768.       re->xvport.attribute = event->u.portNotify.attribute;
  769.       re->xvport.value = event->u.portNotify.value;
  770.       if (_XvOldWireToEventPort) 
  771.     {
  772.       (void)(* _XvOldWireToEventPort)(dpy, re, event);
  773.     }
  774.     }
  775.   else
  776.     {
  777.       return (False);
  778.     }
  779.  
  780.  
  781.   return (True);
  782.   
  783. }
  784.  
  785. Bool
  786. _XvInitExtension(dpy)
  787.  
  788. register Display *dpy;    /* pointer to display structure */
  789.  
  790. {
  791.   int num;
  792.   Bool ss;
  793.  
  794.   if (!(_XvCodes = XInitExtension (dpy, XvName)))
  795.     {
  796.       return False;
  797.     }
  798.  
  799.   _XvOldWireToEventVideo = 
  800.     XESetWireToEvent(dpy, 
  801.              _XvCodes->first_event + XvVideoNotify, 
  802.              _XvWireToEvent);
  803.  
  804.   _XvOldWireToEventPort = 
  805.     XESetWireToEvent(dpy, 
  806.              _XvCodes->first_event + XvPortNotify, 
  807.              _XvWireToEvent);
  808.  
  809.   _XvOldErrorString = XESetErrorString(dpy, _XvCodes->extension, 
  810.                        _XvErrorString);
  811.  
  812.   return True;
  813. }
  814.  
  815. static char *
  816. _XvErrorString(dpy, code, ecodes, buffer, size)
  817.  
  818. register Display *dpy;    /* pointer to display structure */
  819. int code;
  820. XExtCodes *ecodes;
  821. char *buffer;
  822. int size;
  823. {
  824.  
  825.   if (size < strlen("Encoding") + 1)
  826.     {
  827.       if (_XvOldErrorString) 
  828.     return (* _XvOldErrorString)(dpy, code, ecodes, buffer, size);
  829.     }
  830.  
  831.   if (code - ecodes->first_error == XvBadPort)
  832.     {
  833.       strcpy(buffer, "Port");
  834.     }
  835.   else if (code - ecodes->first_error == XvBadEncoding)
  836.     {
  837.       strcpy(buffer, "Encoding");
  838.     }
  839.   else
  840.     {
  841.       if (_XvOldErrorString) 
  842.     return (* _XvOldErrorString)(dpy, code, ecodes, buffer, size);
  843.     }
  844.  
  845.   return (char *)NULL;
  846.  
  847. }
  848.